package com.dapeng.cleardatabackend.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dapeng.cleardatabackend.common.BaseResponse;
import com.dapeng.cleardatabackend.common.ResultUtils;
import com.dapeng.cleardatabackend.model.dto.graph.GraphAddRequest;
import com.dapeng.cleardatabackend.model.dto.graph.GraphGetRequest;
import com.dapeng.cleardatabackend.model.dto.graph.GraphSearchRequest;
import com.dapeng.cleardatabackend.model.dto.graph.GraphUpdateRequest;
import com.dapeng.cleardatabackend.model.vo.GraphVO;
import com.dapeng.cleardatabackend.model.vo.graphdetail.GraphDetailVO;
import com.dapeng.cleardatabackend.service.GraphService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * @author dapeng
 * @description 图谱控制器
 * @date 2024/12/22 13:56
 */
@RestController
@RequestMapping("/graph")
public class GraphController {

    @Resource
    private GraphService graphService;

    /**
     * 添加图谱
     *
     * @param graphAddRequest 添加图形请求
     * @return {@link BaseResponse }<{@link Long }>
     */
    @PostMapping("/add")
    public BaseResponse<Long> addGraph(@ModelAttribute @Valid GraphAddRequest graphAddRequest) {
        Long id = graphService.createGraph(graphAddRequest);
        return ResultUtils.success(id);
    }

    /**
     * 更新图谱
     *
     * @param graphUpdateRequest 更新图谱请求
     * @return {@link BaseResponse }<{@link Boolean }>
     */
    @PostMapping("/update")
    public BaseResponse<Boolean> updateGraph(@RequestBody @Valid GraphUpdateRequest graphUpdateRequest) {
        graphService.updateGraph(graphUpdateRequest);
        return ResultUtils.success(true);
    }

    /**
     * 删除图谱
     *
     * @param id id
     * @return {@link BaseResponse }<{@link Boolean }>
     */
    @DeleteMapping("/{id}")
    public BaseResponse<Boolean> deleteGraph(@PathVariable("id") Long id) {
        return ResultUtils.success(graphService.deleteGraph(id));
    }


    /**
     * 获取我的图谱分页
     *
     * @param graphGetRequest 获取我的图谱请求
     * @return {@link BaseResponse }<{@link Page }<{@link GraphVO }>>
     */
    @PostMapping("/page/my")
    public BaseResponse<Page<GraphVO>> getMyGraphPage(@RequestBody GraphGetRequest graphGetRequest) {
        Page<GraphVO> page = graphService.getMyGraphPage(graphGetRequest);
        return ResultUtils.success(page);
    }

    /**
     * 获取公开图谱列表
     *
     * @param graphGetRequest 获取图谱请求
     * @return {@link BaseResponse }<{@link Page }<{@link GraphVO }>>
     */
    @PostMapping("/page/public")
    public BaseResponse<Page<GraphVO>> getPublicGraphPage(@RequestBody GraphGetRequest graphGetRequest) {
        Page<GraphVO> page = graphService.getPublicGraphPage(graphGetRequest);
        return ResultUtils.success(page);
    }

    /**
     * 搜索图谱
     *
     * @param graphSearchRequest 搜索图谱请求
     * @return {@link BaseResponse }<{@link GraphVO }>
     */
    @PostMapping("/search")
    public BaseResponse<GraphDetailVO> searchGraph(@RequestBody @Valid GraphSearchRequest graphSearchRequest) {
        GraphDetailVO graphDetailVO = graphService.searchGraph(graphSearchRequest);
        return ResultUtils.success(graphDetailVO);
    }
}
